﻿using System.Collections.Generic;
using Shell.DomainDot;
using Framework.Poco;
using System;
using System.Linq;

namespace Framework.Domain
{
    /// <summary>
    /// 文件上传
    /// </summary>
    public class BinaryFileContext : DomainDotBase
    {
        /// <summary>
        /// 所有文件
        /// </summary>
        public WithAll<BinaryFile> BinaryFiles { private get; set; }

        /// <summary>
        /// 获取所有文件
        /// </summary>
        public IEnumerable<BinaryFile> GetAllBinaryFiles()
        {
            return this.BinaryFiles;
        }

        /// <summary>
        /// 根据ID获取一个文件
        /// </summary>
        public BinaryFile GetBinaryFile(Guid identity)
        {
            var picture = this.BinaryFiles.SingleOrDefault(p => p.Id == identity);
            return picture;
        }

        /// <summary>
        /// 添加文件
        /// </summary>
        public BinaryFile CreateBinaryFile(BinaryFile binaryFile)
        {
            var entity = this.BinaryFiles.Create();
            PocoUtils.AssignProperty<BinaryFile>(binaryFile, entity, typeof(Guid));
            this.BinaryFiles.Submit();
            return entity;
        }
    }
}
